package cn.xyfmzmy.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 市
 */
public class City implements PopulationNode{

    private String name;

    // 一个市里包含了多个区
    private List<District> districtList = new ArrayList<>();

    public City(String name) {
        this.name = name;
    }

    public void add(District district){
        this.districtList.add(district);
    }

    @Override
    public int computePopulation() {
        return this.districtList.stream().mapToInt(District::computePopulation).sum();
    }
}
